#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll L = 20;
const ll N = 2e5 + 50;
const ll Mod = 1e9 + 7;
ll n, arr[N], idx[N], inv[N], mid[N], bit[N];
void upd(int x, int y = 1){
for(; x <= n; x += x & (-x)) bit[x] += y;
}
ll get(int x){
ll out = 0;
for(; x; x &= x-1) out += bit[x];
return out;
}
ll fst(ll x){
ll sum = 0, pos = 0;
for(int i = L-1; i >= 0; i--){
if(pos + (1 << i) <= n && sum + bit[pos + (1 << i)] < x){
pos += (1 << i); sum += bit[pos];
}
}
return pos+1;
}
ll c2(ll x){
return x * (x+1) / 2;
}
int main(){
fast_io;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> arr[i]; idx[arr[i]] = i;
}
for(int i = 1; i <= n; i++){
inv[i] = inv[i-1] + i - get(idx[i]) - 1; upd(idx[i]);
mid[i] = fst((i+1)/2);
}
fill(bit, bit+N, 0);
ll sum = 0;
for(int i = 1; i <= n; i++){
upd(idx[i], idx[i]); sum += idx[i];
ll res = inv[i] + ((i+1) / 2 * mid[i] - get(mid[i]) - c2((i+1) / 2 - 1)) + (sum - get(mid[i]) - i/2 * mid[i] - c2(i/2));
cout << res << sep;
}
}
566. Reshape the Matrix | 167. Two Sum II - Input array is sorted |
387. First Unique Character in a String | 383. Ransom Note |
242. Valid Anagram | 141. Linked List Cycle |
21. Merge Two Sorted Lists | 203. Remove Linked List Elements |
733. Flood Fill | 206. Reverse Linked List |
83. Remove Duplicates from Sorted List | 116. Populating Next Right Pointers in Each Node |
145. Binary Tree Postorder Traversal | 94. Binary Tree Inorder Traversal |
101. Symmetric Tree | 77. Combinations |
46. Permutations | 226. Invert Binary Tree |
112. Path Sum | 1556A - A Variety of Operations |
136. Single Number | 169. Majority Element |
119. Pascal's Triangle II | 409. Longest Palindrome |
1574A - Regular Bracket Sequences | 1574B - Combinatorics Homework |
1567A - Domino Disaster | 1593A - Elections |
1607A - Linear Keyboard | EQUALCOIN Equal Coins |